package cn.edu.nuc.ssm.services.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.ssm.dao.UserMapper;
import cn.edu.nuc.ssm.entity.User;
import cn.edu.nuc.ssm.services.interfaces.UserService;

@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserMapper userMapper;
	
	@Override
	public User login(String uname, String upwd) {
		User user = userMapper.selectByPrimaryName(uname);
		
		if (user==null||( ! upwd.equals(user.getUpwd() ) )) {
			throw new RuntimeException("用户名密码错误");
		}
		
		
		return user;
	}

	@Override
	public int register(User user) {
		User u =userMapper.selectByPrimaryName(user.getUname());
		if(u != null){
			
			return 0;
		}
		return userMapper.insertSelective(user);
	}

}
